package com.boco.fznq.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.boco.fznq.R;
import com.culiu.core.utils.view.ViewUtils;

/**
 * Created by jiangcheng on 2016/12/13.
 */

public class TopbarView extends RelativeLayout {

    private Context context;

    private ImageView mIvLeft;

    private ImageView mIvRight;

    private TextView mTvMiddle;


    public TopbarView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        initView();
    }

    public TopbarView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        initView();
    }

    public TopbarView(Context context) {
        super(context);
        this.context = context;
        initView();
    }


    private void initView() {
        inflate(getContext(), R.layout.view_topbar, this);
        mIvLeft = (ImageView) findViewById(R.id.topbar_left);
        mIvRight = (ImageView) findViewById(R.id.topbar_right);
        mTvMiddle = (TextView) findViewById(R.id.topbar_middle);

        mIvLeft.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (leftListener != null) {
                    leftListener.onClick(v);
                }
            }
        });
    }

    public void setLeftImgGone(boolean isGone) {
        ViewUtils.setGone(mIvLeft, isGone);
    }

    /**
     *
     * @param text
     */
    public void setMiddleText(String text) {
        mTvMiddle.setText(text);
    }



    private LeftImgListener leftListener;

    public void setLeftImgListener(LeftImgListener leftListener) {
        this.leftListener = leftListener;
    }

    public interface LeftImgListener {
        void onClick(View view);
    }


}
